package jp.aist.gtrc.plus.admission.EDF.simulation;

public class Event implements Comparable<Event> {
   public static final int INIT = 0;
   public static final int JOB_ARRIVAL = 1;
   public static final int JOB_EXIT = 2;
   public static final int JOB_DEADLINE = 3;
   public static final int TERMINATE = 100;

   private static int lastId = -1;

   private int id;
   private int timestamp;
   private int type;

   public Event(int timestamp,int type) {
      this.id = getNewId();
      this.timestamp = timestamp;
      this.type = type;
      if (timestamp < 0) throw new RuntimeException("Event time cannot be negative.");
   }

   public int getId() {
      return this.id;
   }

   public int getTimestamp() {
      return this.timestamp;
   }

   public int getType() {
      return this.type;
   }

   public synchronized int getNewId() {
      lastId = lastId + 1;
      return lastId;
   }

   public int compareTo(Event e) {
      if (this.timestamp < e.timestamp) {
         return -1;
      } else if (this.timestamp > e.timestamp) {
         return 1;
      } else {
         if (this.id < e.id) {
            return -1;
         } else if (this.id > e.id) {
            return 1;
         } else {
            return 0;
         }
      }
   }

   public String toString() {
      return "event time = " + this.timestamp + ", type = " + this.type;
   }
}
